//
//  MainView.swift
//  SwiftUIFly
//
//  Created by shen on 2023/10/18.
//

import SwiftUI

struct MainView: View {
    /// 错误信息
    @State private var appErrorMessage: String?
    /// 错误提示是否展示
    @State private var showingAppErrorSheet = false

    var body: some View {
        Group {
            SplitView()
                .environment(\.userTint, Color.red)
        }
        .onReceive(NotificationCenter.default.publisher(for: .appErrored, object: nil)) { output in
            if let message = output.userInfo?["message"] as? String {
                appErrorMessage = message
            }
            showingAppErrorSheet = true
        }
        .sheet(isPresented: $showingAppErrorSheet, content: {
            AppErrorSheet(message: $appErrorMessage).interactiveDismissDisabled()
        })
    }
}
